package cn.bingoogolapple.bgabanner;

import ohos.agp.components.Component;

/**
 * 作者:王浩 邮件:bingoogolapple@gmail.com
 * 创建时间:16/12/7 下午9:13
 * 描述:
 */
public abstract class BGAOnNoDoubleClickListener implements Component.ClickedListener {
    private int mThrottleFirstTime = 1000;
    private long mLastClickTime = 0L;

    /**
     * constructor
     */
    public BGAOnNoDoubleClickListener() {
    }

    /**
     * constructor
     *
     * @param throttleFirstTime
     */
    public BGAOnNoDoubleClickListener(int throttleFirstTime) {
        mThrottleFirstTime = throttleFirstTime;
    }

    @Override
    public void onClick(Component component) {
        long currentTime = System.currentTimeMillis();
        if (currentTime - mLastClickTime > mThrottleFirstTime) {
            mLastClickTime = currentTime;
            onNoDoubleClick(component);
        }
    }

    abstract void onNoDoubleClick(Component v);
}
